//
//  JKViewProductDetailHeader.m
//  chequanbao_ios
//
//  Created by 朱凯 on 2018/1/29.
//  Copyright © 2018年 com.itboye. All rights reserved.
//

#import "JKViewProductDetailHeader.h"

@implementation JKViewProductDetailHeader
{
    UIImageView *_iconView;
    UILabel     *_titleLabel;
    UILabel     *_priceLabel;
    UILabel     *_normalPriceLabel;
    UILabel     *_sellsPerMonthLabel;
    UIButton    *_buyButton;
}
- (instancetype)init {
    
    if (self = [super init]) {
        
        self.backgroundColor = [UIColor whiteColor];
        self.layer.cornerRadius = 12;
        self.layer.masksToBounds = true;
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    
    _iconView = [UIImageView new];
    _iconView.image = [UIImage imageNamed:@"商城详情-死图1"];
    [self addSubview:_iconView];
    
    _titleLabel = [UILabel new];
    _titleLabel.numberOfLines = 0;
    _titleLabel.text = @"披萨、糕点、早餐、牛排、欢乐三小时无限畅饮，酒肉鱼肉、美食、电竞";
    _titleLabel.font = FONT(15);
    _titleLabel.textAlignment = NSTextAlignmentLeft;
    _titleLabel.textColor = [UIColor blackColor];
    [self addSubview:_titleLabel];
    
    // 线条
    UIView *line = [UIView new];
    line.backgroundColor = BY_LINE_COLOR;
    [self addSubview:line];

    _buyButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _buyButton.titleLabel.font = FONT(14);
    _buyButton.backgroundColor = rgba(118, 197, 250, 1);
    _buyButton.layer.cornerRadius = 4;
    _buyButton.layer.masksToBounds = true;
    [_buyButton setTitle:@"立即购买" forState:UIControlStateNormal];
    [_buyButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_buyButton addTarget:self action:@selector(buy) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_buyButton];
    
    _priceLabel = [UILabel new];
    _priceLabel.text = @"平台价：68￥";
    _priceLabel.font = FONT(15);
    _priceLabel.textAlignment = NSTextAlignmentLeft;
    _priceLabel.textColor = [UIColor redColor];
    [self addSubview:_priceLabel];

    _normalPriceLabel = [UILabel new];
    _normalPriceLabel.text = @"市场价：80￥";
    _normalPriceLabel.font = FONT(14);
    _normalPriceLabel.textAlignment = NSTextAlignmentLeft;
    _normalPriceLabel.textColor = [UIColor lightGrayColor];
    [self addSubview:_normalPriceLabel];
    
    _sellsPerMonthLabel = [UILabel new];
    _sellsPerMonthLabel.text = @"月售60单";
    _sellsPerMonthLabel.font = FONT(15);
    _sellsPerMonthLabel.textAlignment = NSTextAlignmentLeft;
    _sellsPerMonthLabel.textColor = [UIColor lightGrayColor];
    [self addSubview:_sellsPerMonthLabel];
    
    
    [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(@0);
        make.width.equalTo(self);
        make.height.equalTo(_iconView.mas_width).multipliedBy(0.5);
    }];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.top.equalTo(_iconView.mas_bottom).offset(10);
        make.right.equalTo(@-10);
    }];
    
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(_titleLabel);
        make.top.equalTo(_titleLabel.mas_bottom).offset(10);
        make.height.equalTo(@1);
    }];
    [_buyButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@-10);
        make.width.equalTo(@70);
        make.height.equalTo(@30);
        make.top.equalTo(line.mas_bottom).offset(20);
    }];
    [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(line);
        make.bottom.equalTo(_buyButton.mas_centerY).offset(-2);
    }];
    [_normalPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_priceLabel);
        make.top.equalTo(_buyButton.mas_centerY).offset(2);
    }];
    [_sellsPerMonthLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_normalPriceLabel.mas_right).offset(20);
        make.centerY.equalTo(_normalPriceLabel);
        
        make.bottom.equalTo(@-20);
    }];
  
}

- (void)buy {
    
}

@end
